from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QMainWindow, QWidget,QApplication, QMessageBox
from PyQt5.QtGui import QPixmap
from datetime import datetime  # 导入 datetime 库
import sys  # 导入 sys 库

from package.Utils.ui.QT_MainWindow import Ui_MainWindow  # 导入Ui_MainWindow类(QT设计师创建)

# from Utils.User_Thread import mythread  # 导入 mythread 对象(python代码)
from package.Utils.log import logger,mylog  # 导入 logger 对象(python代码)
from package.Utils.Screen import screen   # 导入 screen 对象(python代码)
# from Utils.User_Import import *  # 导入 myWin, screen, logger, Ui_MainWindow 对象(python代码)

#图片路径
img_relative_path = './image/'

class MyWinUtils:
    def __init__(self):
        self.img = [f'{img_relative_path}1.jpg', f'{img_relative_path}2.jpg', f'{img_relative_path}3.jpg']
        self.img_index = 0
        self.pix = 0
        self.click_button4_Flag = False  # 初始化点击 pushButton_4 标志位
        self.click_radioButton_Index = 1  # 初始化点击 radioButton 索引

class MyMainWindow(QMainWindow, Ui_MainWindow): # 继承 QMainWindow类和 Ui_MainWindow界面类
    def __init__(self, parent=None):
        super(MyMainWindow, self).__init__(parent)  # 初始化父类
        self.setupUi(self)  # 继承 Ui_MainWindow 界面类

        self.mywinutils = MyWinUtils()

        self.stackedWidget_Index = 0  # 初始化 stackedWidget 索引
        self.stackedWidget.setCurrentIndex(self.stackedWidget_Index)  # 默认界面0

        self.MousePosition_information_msg = QMessageBox()  # 初始化 QMessageBox 对象
        self.Screen_information_msg = QMessageBox()  # 初始化 QMessageBox 对象
        self.MousePosition_information_msg.setWindowModality(Qt.NonModal)  # 设置QMessageBox窗口模式
        self.Screen_information_msg.setWindowModality(Qt.NonModal)  # 设置QMessageBox窗口模式

    #单击 获取屏幕分辨率 按钮
    def click_pushButton_GetScreen(self):
        if mylog.log_enabled is True:
            logger.info('点击了获取屏幕分辨率按钮')
        screen.get_Screen_ResolutionRatio()
        self.Screen_information_msg.information(self, '获取屏幕分辨率', f'当前屏幕分辨率为：{screen.width} x {screen.height}', QMessageBox.Yes)

    #单击 获取鼠标位置 按钮
    def click_pushButton_GetMousePosition(self):
        if mylog.log_enabled is True:
            logger.info('点击了获取鼠标位置按钮')
        screen.get_Mouse_Position()
        # self.MousePosition_information_msg.information(self, '获取鼠标位置', f"当前鼠标位置为：{screen.Mouse_Position_x,screen.Mouse_Position_y}", QMessageBox.Yes)
        self.MousePosition_information_msg.setWindowTitle('获取鼠标位置')
        self.MousePosition_information_msg.setText(f"当前鼠标位置为：{screen.Mouse_Position_x,screen.Mouse_Position_y}")
        self.MousePosition_information_msg.setStandardButtons(QMessageBox.Yes)
        self.MousePosition_information_msg.show()
        from Utils.User_Thread import mythread  # 导入 mythread 对象(python代码)
        mythread.Start()

    #单击 开始 按钮
    def click_pushButton_Start(self):
        if self.mywinutils.click_radioButton_Index == 1:    #QQ轰炸机
            if mylog.log_enabled is True:
                logger.info('启动Task1窗口')
            myTask1Win.show()  # 显示任务1窗口
        elif self.mywinutils.click_radioButton_Index == 2:    #批量替换文件内容
            if mylog.log_enabled is True:
                logger.info('启动Task2窗口')
            myTask2Win.show()  # 显示任务2窗口

    #单击 停止 按钮
    def click_pushButton_Stop(self):
        pass

    #单击 QQ轰炸机 按钮
    def click_radioButton_Task1(self):
        self.mywinutils.click_radioButton_Index = 1  # 记录选择的radioButton索引
        self.label_task.setText('选择要运行的任务：QQ轰炸机')
        if mylog.log_enabled is True:
            logger.info('选择了QQ轰炸机')

    #单击 批量替换文件内容 按钮
    def click_radioButton_Task2(self):
        self.mywinutils.click_radioButton_Index = 2  # 记录选择的radioButton索引
        self.label_task.setText('选择要运行的任务：批量替换文件内容')
        if mylog.log_enabled is True:
            logger.info('选择了批量替换文件内容')

    #单击 Task2 按钮
    def click_radioButton_Task3(self):
        self.mywinutils.click_radioButton_Index = 3  # 记录选择的radioButton索引
        self.label_task.setText('选择要运行的任务：Task3')
        if mylog.log_enabled is True:
            logger.info('选择了Task3')

    #单击 日志记录 复选框
    def click_checkBox_LogChoose(self):
        if self.checkBox_LogChoose.isChecked():
            mylog.log_enabled = True
            logger.info('日志记录已开启')
        else:
            mylog.log_enabled = False
            logger.info('日志记录已关闭')

    #双击 侧边菜单栏
    def doubleClick_TreeWeight(self):
        item = self.treeWidget.currentItem()  # 获取当前 treeWidget 点击项
        if item.text(0) == '初始化':
            self.stackedWidget_Index = 0  # 切换初始化界面
            self.stackedWidget.setCurrentIndex(self.stackedWidget_Index)  # 显示界面
            if mylog.log_enabled is True:
                logger.info('切换到初始化界面')
        elif item.text(0) == '任务':
            self.stackedWidget_Index = 1  # 切换任务界面
            self.stackedWidget.setCurrentIndex(self.stackedWidget_Index)  # 显示界面
            if mylog.log_enabled is True:
                logger.info('切换到任务界面')
        elif item.text(0) == '设置':
            self.stackedWidget_Index = 2  # 切换设置界面
            self.stackedWidget.setCurrentIndex(self.stackedWidget_Index)  # 显示界面
            if mylog.log_enabled is True:
                logger.info('切换到设置界面')
        else:
            pass

    #单击 点赞 按钮
    def click_pushButton_Good(self):
        self.stackedWidget_Index = 3  # 切换点赞投喂界面
        self.stackedWidget.setCurrentIndex(self.stackedWidget_Index)  # 显示界面
        if mylog.log_enabled is True:
            logger.info('点击了点赞按钮')

app = QApplication(sys.argv)  # 在 QApplication 方法中使用，创建应用程序对象
myWin = MyMainWindow()  # 实例化 MyMainWindow 类，创建主窗口

from package.Utils.Task1Window import MyTask1Window  # 导入 MyTask1Window 类(python代码)
myTask1Win = MyTask1Window()  # 实例化 MyTask1Window 类，创建Task1窗口对象

from package.Utils.Task2Window import MyTask2Window  # 导入 MyTask2Window 类(python代码)
myTask2Win = MyTask2Window()  # 实例化 MyTask2Window 类，创建Task2窗口对象